﻿using AntdUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 纺织贸易管理系统;

namespace PrintLabel.View
{
    public partial class FabricSelectFrm : AntdUI.BaseForm 
    {
        public OrderDetailTable selectdb { get; set; }
        public FabricSelectFrm()
        {
            InitializeComponent();
            table1.AutoSizeColumnsMode = AntdUI.ColumnsMode.Fill; 
            var btns = new CellLink[] { new CellButton("修改") };
            table1.Columns = new AntdUI.ColumnCollection()
            {
                 new AntdUI.Column ("OrderNum","订单号"),
                new AntdUI.Column ("sampleNum","编号"),
                new AntdUI.Column ("sampleName","品名"),
                 new AntdUI.Column ("CustomerPingMing","客户品名"),
                 new AntdUI.Column ("color","颜色"),
                   new AntdUI.Column ("CustomerColorNum","客户颜色"),
                 new AntdUI.Column ("Kuanhao","款号"),
                  new AntdUI.Column ("danwei","单位"),
                 new AntdUI.Column ("Num","订单需求数"),
            };
            QueryFabric(1 );
        }

        private void button1_Click(object sender, EventArgs e)
        {
            QueryFabric(1);
        }
        private void QueryFabric(int current)
        {
            int total = 0;
            table1.DataSource=dbContext.dbcontext.Queryable<OrderDetailTable>().Where(x=>x.sampleNum.Contains(txtbianhao.Text )&&x.sampleName.Contains (txtpingming.Text )&&x.OrderNum.Contains (txtOrderNum.Text )).OrderByDescending(x=>x.ID).ToPageList(current, pagination1.PageSize, ref total);
            pagination1.Total = total;
        }

        private void txtbianhao_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) {
                QueryFabric(1);
            }
        }

        private void table1_CellDoubleClick(object sender, MouseEventArgs args, object record, int rowIndex, int columnIndex, Rectangle rect)
        {
            selectdb=record as OrderDetailTable ;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(table1.SelectedIndex>=0)
            {
                var dbs= table1.DataSource as List<OrderDetailTable>;
                selectdb = dbs[table1.SelectedIndex - 1];
                this.Close();
            }
        }

        private void pagination1_ValueChanged(int current, int total, int pageSize, int pageTotal)
        {
            QueryFabric(current );
        }
    }
}
